<!doctype html>
<html>
	<head>
		<title>定时任务管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
		<link href='css/bootstrap.min.css' rel="stylesheet" />
		<link href="css/style.css" type="text/css" rel="stylesheet"/>
    	<script type="text/javascript" src="js/jquery.min.js"></script>
		<script src="js/lang.js" type="text/javascript" charset="utf8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf8"></script>
	</head>
	<body>
		
		<div class="container-fluid">
      		<div class="row-fluid">
        		<div class="span12">
          				<h3>Trigger Stat</h3>
						<table id="dataTable" class="table table-bordered table-striped responsive-utilities">
							<thead>
								<tr>
									<th><a href="javascript:void(0);" class="lang" langKey="No">No</a></th>
									<th><a id="th-beanName" href="javascript:void(0);" class="lang" langKey="TriggerName">Trigger Name</a></th>
									<th><a id="th-description" href="javascript:void(0);" class="lang" langKey="Description">Description</a></th>
									<th><a id="th-cronExpression" href="javascript:void(0);" class="lang" langKey="CronExpression">Cron Expression</a></th>
									<th><a id="th-previousFire" href="javascript:void(0);" class="lang" langKey="PreviousFire">Previous Fire</a></th>
									<th><a id="th-nextFire" href="javascript:void(0);" class="lang" langKey="NextFire">Next Fire</a></th>
									<th><a id="th-status" href="javascript:void(0);" class="lang" langKey="TriggerStatus">Trigger Status</a></th>
									<th><a id="th-machineIp" href="javascript:void(0);" class="lang" langKey="MachineIp">Machine IP</a></th>
									<th><a id="th-machineHost" href="javascript:void(0);" class="lang" langKey="MachineHost">Machine Host</a></th>
									<th><a id="th-updateTime" href="javascript:void(0);" class="lang" langKey="UpdateTime">Update Time</a></th>
									<th><a id="th-createTime" href="javascript:void(0);" class="lang" langKey="CreateTime">Create Time</a></th>
									<th><a id="th-memo" href="javascript:void(0);" class="lang" langKey="Memo">Memo</a></th>
									<th><a href="javascript:void(0);" class="lang" langKey="Operator">Operator</a></th>
								</tr>
							</thead> 
							<tbody></tbody>
						</table>
          			</div>
        		</div>
    	</div>
    	<script type="text/javascript">
	    	$.namespace("common.trigger");
	    	common.trigger = function () {  
	    		return  {
	    			init : function() {
	    				common.common.buildHead(2);
	    				$("#dataTable th a").click(function(obj) {
	    					if(obj.target.id != null){
	    						common.common.setOrderBy(obj.target.id.substring(3));
	    					}
	    				});
	    				common.common.ajaxuri = 'trigger/loadAll.json?';
	    				common.common.handleAjaxResult = common.trigger.handleAjaxResult;
	    				common.common.ajaxRequestForBasicInfo();
	    				setInterval("common.common.ajaxRequestForBasicInfo();",5000);
	    			},
	    			
	    			handleAjaxResult : function(result) {
	    				if(result.success==false){
	    					var msg = common.common.buildError(result.message);
	    					$("#dataTable tbody").html("<tr><td colspan='6'>"+msg+"</td></tr>");
	    					return;
	    				}
	    				var dataList = result.data.list;
	    				if(result.success == true && dataList.size == 0){
	    					var msg = common.common.buildNotRecordFound();
	    					$("#dataTable tbody").html("<tr><td colspan='6'>"+msg+"</td></tr>");
	    					return;
	    				}
	    				
	    				var seqStatTable = document.getElementById("dataTable");
	    				while (seqStatTable.rows.length > 1) {
	    					seqStatTable.deleteRow(1);
	    				}
	    				
	    				var html = "";
	    				for ( var i = 0; i < dataList.length; i++) {
	    					var data = dataList[i];
	    					console.info(new Date(data.previousFire));
	    					var newRow = seqStatTable.insertRow(-1);
	    					html += "<tr>";
	    					html += "<td>" + data.triggerId + "</td>";
	    					html += "<td>" + data.beanName + "</td>";
	    					html += "<td>" + data.description + "</td>";
	    					html += "<td>" + data.cronExpression + "</td>";
	    					html += "<td>" + common.common.dateFormat(new Date(data.previousFire)) + "</td>";
	    					html += "<td>" + common.common.dateFormat(new Date(data.nextFire)) + "</td>";
	    					html += "<td>" + common.common.formatTriggerStatus(data.status) + "</td>";
	    					html += "<td>" + data.machineIp + "</td>";
	    					html += "<td>" + data.machineHost + "</td>";
	    					html += "<td>" + common.common.dateFormat(new Date(data.updateTime)) + "</td>";
	    					html += "<td>" + common.common.dateFormat(new Date(data.createTime)) + "</td>";
	    					html += "<td>" + replace(data.memo) + "</td>";
	    					html += "<td><a href='javascript:void(0);' onclick=fireTrigger('"+data.beanName+"') class='lang' langKey='Fire'>Fire</a>";
	    					if(data.status == 'NORMAL'){
	    						html +="|<a href='javascript:void(0);' onclick=pauseTrigger('"+data.beanName+"') class='lang' langKey='Pause'>Pause</a>";
	    					}else if(data.status == 'PAUSE'){
	    						html +="|<a href='javascript:void(0);' onclick=resumeTrigger('"+data.beanName+"') class='lang' langKey='Resume'>Resume</a>";
	    					}
	    					html += "</td>";
	    					html += "</tr>";
	    				}
	    				$("#dataTable tbody").html(html);
	    				common.common.stripes();
	    				common.lang.init();
	    			}
	    		}
	    	}();
	
	    	$(document).ready(function() {
	    		common.trigger.init();
	    	});
	    	
	    	function fireTrigger(name){
	    		if(!confirm("Are you sure to fire this trigger?")){
					return;
				}
	    		common.common.ajaxuri = 'trigger/fireTrigger.json?triggerName='+name+"&";
				common.common.handleAjaxResult = function(result){
					if(result.success == true){
						window.location.reload();
					}
					common.common.ajaxuri = 'trigger/loadAll.json?';
				};
	    	}
	    	function pauseTrigger(name){
	    		if(!confirm("Are you sure to pause this trigger?")){
					return;
				}
	    		common.common.ajaxuri = 'trigger/pauseTriggers.json?triggerName='+"&";
				common.common.handleAjaxResult = function(result){
					if(result.success == true){
						window.location.reload();
					}
					common.common.ajaxuri = 'trigger/loadAll.json?';
				};
	    	}
	    	function resumeTrigger(name){
	    		if(!confirm("Are you sure to resume this trigger?")){
					return;
				}
	    		common.common.ajaxuri = 'trigger/resumeTriggers.json?triggerName='+"&";
				common.common.handleAjaxResult = function(result){
					if(result.success == true){
						window.location.reload();
					}
					common.common.ajaxuri = 'trigger/loadAll.json?';
				};
	    	}
		</script>
	</body>
</html>
